home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-1.iso / Files / Newton / Apps / Runner's Log.sit / Runner's Log / Runner.txt < prev    next >
Encoding:
Text File  |  1994-03-23  |  12.0 KB  |  414 lines  |  [TEXT/MPS ]

  1. constant kAppSymbol := '|Runner:SOAPNOTES|;
  2. constant kPackageName :="Runner:SOAPNOTES";
  3. constant kAppObject := '["mile", "miles", "minute", "minutes", "month",       "months","year", "years"];
  4. constant kSoupName := kPackageName;
  5. constant kSoupIndexes := '[{structure: slot, path: rundate, type:int}];
  6.  
  7.  
  8. //RemoveScript:= func(partFrame)
  9. //begin
  10. //foreach store in GetStores() do begin
  11. //local soup :=store:GetSoup(kSoupName);
  12. //if soup then soup:RemoveFromStore();
  13. //end;
  14. //end;
  15.  
  16.  
  17.  
  18.                                                        
  19.  
  20.  
  21. // ---- End Project Data ----
  22. RunBase :=
  23.    {title: "Runner's Log",
  24.     viewBounds: {left: 2, top: 2, right: 242, bottom: 337},
  25.     viewflags: 516,
  26.     documentation:
  27.       "This sample app shows how to create a mostly working clMonthView based date\npickerlike the one in the preferences or dates applications.  It uses bitmaps in\nthe system ROMs for left and right buttons, has a month/year display that\nupdates, and should size itself appropriately for the view that it's been dragged\nout in.\n\nThe meat is now a nice user proto.  Feel free to use all or part of it in your apps.\n\n            --Bob (for PIE DTS)"
  28.     ,
  29.     viewSetupFormScript:
  30.       func()
  31.       begin
  32.           selectedDates := [Time()];
  33.           :RegisterCardSoup(kSoupName, kSoupIndexes, kAppSymbol, kAppObject);
  34.       end,
  35.     RegisterCardSoup:
  36.       func(SoupName, SoupIndexes, AppSymbol, AppObject)
  37.           begin
  38.          if functions.RegisterCardSoup then
  39.             return RegisterCardSoup(SoupName, SoupIndexes, AppSymbol, AppObject);
  40.             CreateAppSoup(SoupName, SoupIndexes, EnsureInternal([AppSymbol]), EnsureInternal(AppObject));
  41.             AddArraySlot(CardSoups, SoupName);
  42.             AddArraySlot(CardSoups, SoupIndexes);
  43.             local store;
  44.             foreach store in GetStores() do
  45.                if NOT Store:IsReadOnly() AND NOT store:HasSoup(SoupName) then
  46.                   store:CreateSoup(SoupName, SoupIndexes);
  47.           end,
  48.     UnRegisterCardSoup:
  49.       func(soupName)
  50.           begin
  51.          if functions.UnRegisterCardSoup then
  52.             return UnRegisterCardSoup(SoupName);
  53.          local pos := ArrayPos(CardSoups, SoupName, 0, func(x,y) ClassOf(y) ='String AND StrEqual(x,y));
  54.             if pos then ArrayRemoveCount(CardSoups, pos, 2);
  55.           end,
  56.     viewQuitScript:
  57.       func()
  58.       begin
  59.       selectedDates := nil;
  60.       :UnRegisterCardSoup(kSoupName);
  61.       end   ,
  62.     selectedDates: [],
  63.     _proto: protoApp,
  64.     debug: "RunBase"
  65.    };
  66.  
  67.  
  68. protoDatePicker :=
  69.    {viewflags: 1,
  70.     viewFormat: nil,
  71.     viewBounds: {left: 0, top: 0, right: 120, bottom: 100},
  72.     monthChangedScript:
  73.       func()
  74.       begin
  75.           // This will be inherited by the child month view and called every time
  76.           // the user taps on a new day.  It *must* be here because the user can
  77.           // tap on days at the end or beginning of the previous or next month
  78.           // (the blank spaces on the view) and actually change the date!
  79.           // If this script isn't here to update the view and the title string,
  80.           // the month with change but the display won't--confusing the heck out of
  81.           // people.
  82.           :Dirty();
  83.           :SetTitle();
  84.       end,
  85.     monthYearSpec:
  86.       GetDateStringSpec([
  87.               [kElementMonth, kFormatLong],
  88.               [kElementYear,  kFormatLong]]),
  89.     SetTitle:
  90.       // This function updates the month/year label.  It should be called
  91.       // whenever the user changes the date.
  92.       
  93.       func()
  94.       begin
  95.           SetValue(monthYearLabel, 'text,
  96.                    LongDateStr(selectedDates[0], monthYearSpec));
  97.       end,
  98.     viewSetupDoneScript:
  99.       func()
  100.       begin
  101.           if NOT selectedDates exists then
  102.               self.selectedDates := [Time()];  // initialize selectedDates to current
  103.           :SetTitle();
  104.       end,
  105.     Refresh:
  106.       // This allows scripts outside the proto to have a nice entry point for
  107.       // getting the picker refreshed when the selectedDates array changes.
  108.       
  109.       func()
  110.       begin
  111.           monthView:Dirty();
  112.           :SetTitle();
  113.       end,
  114.     viewclass: 74,
  115.     debug: "protoDatePicker"
  116.    };
  117.  
  118. monthYearLabel := /* child of protoDatePicker */
  119.    {text: "",
  120.     viewBounds: {left: 0, top: 0, right: 0, bottom: 15},
  121.     viewflags: 3,
  122.     viewJustify: 8388662,
  123.     _proto: protoStaticText,
  124.     debug: "monthYearLabel"
  125.    };
  126. // View monthYearLabel is accesible from protoDatePicker
  127.  
  128.  
  129.  
  130. previousMonthButton := /* child of protoDatePicker */
  131.    {viewBounds: {left: 0, top: 0, right: 15, bottom: 15},
  132.     viewSetupFormScript:
  133.       func()
  134.       begin
  135.           // initialize the icon from the system bitmap via a magic pointer.
  136.           self.icon := @325;    // leftBitmap
  137.       end,
  138.     viewflags: 515,
  139.     viewJustify: 6,
  140.     viewFormat: 1,
  141.     buttonPressedScript:
  142.       func()
  143.       begin
  144.           // move to the previous month, and make sure the views redraw.
  145.           selectedDates[0] := IncrementMonth(selectedDates[0], -1);
  146.           monthView:dirty();
  147.           :SetTitle();
  148.       
  149.           // have to call RefreshViews because this is the buttonPressedScript,
  150.           // the view otherwise wouldn't get refreshed until the user lifted the
  151.           // pen!  If you had done this in the buttonClickScript instead, you
  152.           // could skip the RefreshViews() call.
  153.           RefreshViews();
  154.       end,
  155.     icon: nil,
  156.     _proto: protoPictureButton,
  157.     debug: "previousMonthButton"
  158.    };
  159.  
  160.  
  161.  
  162. nextMonthButton := /* child of protoDatePicker */
  163.    {icon: nil,
  164.     viewBounds: {top: 0, left: -15, right: 0, bottom: 15},
  165.     viewSetupFormScript:
  166.       func()
  167.       begin
  168.           // initialize the bitmap from the system ROMs via a magic pointer.
  169.           self.icon := @326;    // rightBitmap
  170.       end,
  171.     viewflags: 515,
  172.     viewFormat: 1,
  173.     viewJustify: 38,
  174.     buttonPressedScript:
  175.       func()
  176.       begin
  177.           // move to the previous month, and make sure the views redraw.
  178.           selectedDates[0] := IncrementMonth(selectedDates[0], 1);
  179.           monthView:dirty();
  180.           :SetTitle();
  181.       
  182.           // have to call RefreshViews because this is the buttonPressedScript,
  183.           // the view otherwise wouldn't get refreshed until the user lifted the
  184.           // pen!  If you had done this in the buttonClickScript instead, you
  185.           // could skip the RefreshViews() call.
  186.           RefreshViews();
  187.       end,
  188.     _proto: protoPictureButton,
  189.     debug: "nextMonthButton"
  190.    };
  191.  
  192.  
  193.  
  194. monthView := /* child of protoDatePicker */
  195.    {viewBounds: {top: 15, left: 1, right: -1, bottom: -1},
  196.     viewflags: 513,
  197.     viewFormat: nil,
  198.     labelFont: ROM_fontSystem9Bold,
  199.     dateFont: ROM_fontSystem9,
  200.     viewJustify: 246,
  201.     singleDay: true,
  202.     viewclass: 80,
  203.     debug: "monthView"
  204.    };
  205. // View monthView is accesible from protoDatePicker
  206.  
  207.  
  208.  
  209.  
  210. datePicker := /* child of RunBase */
  211.    {viewBounds: {left: 25, top: 209, right: 145, bottom: 297},
  212.     viewFormat: 336,
  213.     _proto: protoDatePicker,
  214.     debug: "datePicker"
  215.    };
  216. // View datePicker is accesible from RunBase
  217.  
  218.  
  219.  
  220. _view000 := /* child of RunBase */
  221.    {text: "Today",
  222.     buttonClickScript:
  223.       func()
  224.       begin
  225.           selectedDates := [Time()];
  226.           datePicker:Refresh();
  227.           RunMonth:SyncView();
  228.           RunYear:SyncView();
  229.       end,
  230.     viewBounds: {left: 178, top: 242, right: 222, bottom: 262},
  231.     _proto: protoTextButton
  232.    };
  233.  
  234.  
  235.  
  236. _view001 := /* child of RunBase */
  237.    {text: "Minutes",
  238.     viewBounds: {left: 72, top: 56, right: 120, bottom: 72},
  239.     _proto: protoStaticText
  240.    };
  241.  
  242.  
  243.  
  244. _view002 := /* child of RunBase */
  245.    {text: "Miles",
  246.     viewBounds: {left: 144, top: 56, right: 176, bottom: 72},
  247.     _proto: protoStaticText
  248.    };
  249.  
  250. _view003 := /* child of _view002 */
  251.    {viewBounds: {left: 32, top: 16, right: 72, bottom: 32},
  252.     viewflags: 10753,
  253.     _proto: protoInputLine
  254.    };
  255.  
  256.  
  257.  
  258.  
  259.  
  260. _view004 := /* child of RunBase */
  261.    {text: "Totals Month",
  262.     viewBounds: {left: 8, top: 144, right: 80, bottom: 160},
  263.     _proto: protoStaticText
  264.    };
  265.  
  266.  
  267.  
  268. _view005 := /* child of RunBase */
  269.    {text: "Totals Year",
  270.     viewBounds: {left: 152, top: 144, right: 216, bottom: 160},
  271.     _proto: protoStaticText
  272.    };
  273.  
  274.  
  275.  
  276. _view006 := /* child of RunBase */
  277.    {text: "Save",
  278.     buttonClickScript:
  279.       func()
  280.       begin
  281.          entry :={rundate: selectedDates[0], miles: Runmiles.text, minutes: Runminutes.text};
  282.          soup := GetUnionSoup(kSoupName);
  283.          soup:AddToDefaultStore(entry);
  284.          EntryChange(entry);
  285.          SetValue(Runmiles, 'text, "");
  286.          SetValue(Runminutes, 'text, "");
  287.          RunMonth:SyncView();
  288.          RunYear:SyncView();
  289.       end,
  290.     viewBounds: {left: 178, top: 274, right: 222, bottom: 294},
  291.     _proto: protoTextButton
  292.    };
  293.  
  294.  
  295.  
  296. Runminutes := /* child of RunBase */
  297.    {viewBounds: {left: 72, top: 80, right: 112, bottom: 104},
  298.     viewflags: 10757,
  299.     _proto: protoInputLine,
  300.     debug: "Runminutes"
  301.    };
  302. // View Runminutes is accesible from RunBase
  303.  
  304.  
  305.  
  306. Runmiles := /* child of RunBase */
  307.    {viewBounds: {left: 136, top: 80, right: 176, bottom: 104},
  308.     viewflags: 10757,
  309.     _proto: protoInputLine,
  310.     debug: "Runmiles"
  311.    };
  312. // View Runmiles is accesible from RunBase
  313.  
  314.  
  315.  
  316. RunMonth := /* child of RunBase */
  317.    {text: "",
  318.     viewBounds: {left: 16, top: 168, right: 80, bottom: 192},
  319.     viewflags: 7,
  320.     viewDrawScript:
  321.       func()
  322.           begin 
  323.          local runtemp :=(Date(selectedDates[0]));
  324.          local runmonth := runtemp.month;
  325.          local runyear := runtemp.year;
  326.          mysoup := GetUnionSoup(kSoupName);
  327.          local cursor := Query(mysoup, {type: 'index, indexPath: 'rundate, validTest: func(e) (Date(e.rundate)).year = runyear AND (Date(e.rundate)).month = runmonth});
  328.          local entry := cursor:Entry();
  329.          local vcounter := 0;
  330.          local mcounter := 0;
  331.          while entry do begin
  332.                vcounter := vcounter + StringToNumber(entry.miles);
  333.                mcounter := mcounter + StringToNumber(entry.minutes);
  334.                entry := cursor:Next();
  335.          end;
  336.          SetValue(self, 'text, NumberStr(mcounter) && "/" && NumberStr(vcounter));
  337.           end,
  338.     _proto: protoStaticText,
  339.     debug: "RunMonth"
  340.    };
  341. // View RunMonth is accesible from RunBase
  342.  
  343.  
  344.  
  345. RunYear := /* child of RunBase */
  346.    {text: "",
  347.     viewBounds: {left: 152, top: 168, right: 216, bottom: 192},
  348.     viewflags: 7,
  349.     viewDrawScript:
  350.       func()
  351.           begin
  352.          local runtemp :=(Date(selectedDates[0]));
  353.          local runmonth := runtemp.month;
  354.          local runyear := runtemp.year;
  355.          mysoup := GetUnionSoup(kSoupName);
  356.          local cursor := Query(mysoup, {type: 'index, indexPath: 'rundate, validTest: func(e) (Date(e.rundate)).year = runyear});
  357.          local entry := cursor:Entry();
  358.          local vcounter := 0;
  359.          local mcounter := 0;
  360.          while entry do begin
  361.                vcounter := vcounter + StringToNumber(entry.miles);
  362.                mcounter := mcounter + StringToNumber(entry.minutes);
  363.                entry := cursor:Next();
  364.          end;
  365.          SetValue(self, 'text, NumberStr(mcounter) && "/" && NumberStr(vcounter));
  366.           end,
  367.     _proto: protoStaticText,
  368.     debug: "RunYear"
  369.    };
  370. // View RunYear is accesible from RunBase
  371.  
  372.  
  373.  
  374. CreditLink := /* child of RunBase */
  375.    {viewBounds: {left: 0, top: 102, right: 228, bottom: 290},
  376.     _proto: protoFloatNGo,
  377.     debug: "CreditLink"
  378.    };
  379.  
  380. _view007 := /* child of CreditLink */
  381.    {viewflags: 1,
  382.     viewFormat: 257,
  383.     viewLineSpacing: 20,
  384.     viewfont: Rom_FontSystem9,
  385.     viewBounds: {left: 0, top: 0, right: 240, bottom: 168},
  386.     text:
  387.       "Runner is freeware by S.O.A.P. Notes, Inc.\nLincoln, Nebr. 1994 based on Mike Eberts PDK demo of the protodatePicker\nIf you make changes to improve it send us a copy\n3140 \"O\" Street\nLincoln, Ne 68510\n(800) 635-2481\n"
  388.     ,
  389.     viewclass: 81
  390.    };
  391.  
  392.  
  393. // View CreditLink is accesible from RunBase
  394.  
  395.  
  396.  
  397. ShowCredits := /* child of RunBase */
  398.    {text: "?",
  399.     buttonClickScript:
  400.       func()
  401.           begin
  402.          CreditLink:open()
  403.           end,
  404.     viewBounds: {left: 114, top: 306, right: 130, bottom: 322},
  405.     viewFormat: 251658833,
  406.     viewfont: ROM_fontSystem12Bold,
  407.     _proto: protoTextButton,
  408.     debug: "ShowCredits"
  409.    };
  410.  
  411.  
  412.  
  413.  
  414.